﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Linq.Expressions;
using Newtonsoft.Json.Linq;
using WebGrease.Css.Extensions;

using CanDoo;
using CanDoo.Core;
using CanDoo.Data;
using CanDoo.Web;
using CanDoo.FineUI;
using CanDoo.Extensions;
using CanDoo.Admin.Core.Models;
using CanDoo.Admin.Core.Contracts;
using CanDoo.Core.Data;

namespace CanDoo.Oil.WebHost.ViewBulletin
{
    public partial class Detail : PageBase
    {
        public string Title, Name, CreateTime, ContentInfo, Other = "";
        public IBulletinContract _iBulletinContract { get; set; }
        public IAttachmentContract _iAttachmentContract { get; set; }
        protected void Page_Load(object sender, EventArgs e)
        {
            var Id = CanDoo.Web.Request.QueryString("Id").ToLong();
            if (Id == 0)
            {
                Response.Write("参数错误！");
                Response.End();
            }

            DB.KeepReading(() =>
            {
                var Entity = _iBulletinContract.GetById(Id);
                if (Entity != null)
                {
                    Title = Entity.Name;
                    Name = Entity.User.Name;
                    CreateTime = string.Format("{0:yyyy-MM-dd}", Entity.CreateDate);
                    ContentInfo = Entity.Content;

                    var aList = _iAttachmentContract.Entities.Where(p => p.EntityId == Entity.Id && p.IsDeleted == false).ToList();
                    if (aList != null && aList.Count > 0)
                    {
                        Other += "<div class=\"other\">\r\n";
                        Other += "<h2>附件<br>\r\n";
                        foreach (var m in aList)
                        {
                            Other += "<a href=\"/Code/DownLoad.aspx?Id=" + m.Id + "\" target=\"_ablank\">" + m.Name + "</a><br>\r\n";
                        }
                        Other += "</div>\r\n";
                    }
                }
                else
                {
                    Response.Write("参数错误！");
                    Response.End();
                }
            }); 
        }
    }
}